import {
  getDepList,
  // getHospList,
  // getSysHospitalGetList,
  getModalityList
} from '@/api/api'
import $store from '../store'
import { getLocalStorage } from '@/utils/localStorage'
export default {
  data() {
    return {
      mx_hospitalCode: $store.state.user.hospitalCode,
      mx_hospitalList: [],
      mx_deplist: [],
      mx_modalitylist: []
    }
  },
  created() {

  },
  mounted() {
    // this.$getHospitalList()
  },
  methods: {
  // 获取医院列表
    async $getHospitalList() {
      // console.log('$getHospitalList-1')
      const storageHospital = getLocalStorage('hospitalOptions') && JSON.parse(getLocalStorage('hospitalOptions')) || ''
      // console.log('storageHospital', storageHospital)
      if (storageHospital && storageHospital.length > 0) {
        this.mx_hospitalList = storageHospital
      } else {
        const hospList = await $store.dispatch('user/getHospitalOptions')
        this.mx_hospitalList = hospList
      }
      // console.log('this.mx_hospitalList', this.mx_hospitalList)
    },
    // 获取检查部门
    $getDeplist(hospCode) {
      if (!hospCode) {
        this.mx_deplist = []
        this.mx_modalitylist = []
        return
      }
      const params = {
        HospitalCode: hospCode
      }
      getDepList(params).then(res => {
        if (res) {
          this.mx_deplist = this.mx_deplist.concat(res.content.list)
          this.mx_modalitylist = []
          this.$getModalitylist('', hospCode)
        } else {
          this.mx_deplist = []
          this.mx_modalitylist = []
        }
      })
    },
    // 获取检查设备
    $getModalitylist(dep, hospCode) {
    // if (!dep) {
    //   this.mx_modalitylist = []
    //   return
    // }
      const params = {
        HospitalCode: !hospCode ? this.mx_hospitalCode : hospCode,
        Dep: dep
      }
      getModalityList(params).then(res => {
        if (res) {
          this.mx_modalitylist = this.mx_modalitylist.concat(res.content.list)
        } else {
          this.mx_modalitylist = []
        }
      })
    },
    $hasPermission(perArr) {
      let tags = $store.state.user.tags
      if (tags && perArr && perArr.length > 0) {
        for (let p of perArr) {
          if (tags.indexOf(p) > -1) {
            return true
          }
        }
      }
      return false
    }
  }
}
